<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <title>Welcome to Vue</title>
</head>
<style>
    body {
        padding: 20px 100px;
        background-color: #ccc;
    }

    #aut {
        box-shadow: 0 0 8px 3px rgb(89, 207, 243);
        border-radius: 10px;
    }

    #auts {
        border-radius: 10px;

    }

    .flex {
        display: flex;
        align-items: center;
    }
</style>

<body>
    <div id="app">
        <el-input id="auts" style="width: 200px;" v-model="input" placeholder="请输入内容"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="searchBtn" circle></el-button>
        <el-button type="success" icon="el-icon-edit" @click="addBtn" circle></el-button>
        <br>
        <br>
        <!-- 主题 -->
        <template>
            <el-table id="aut" ref="dataList" :data="dataList" tooltip-effect="dark" style="width: 100%"
                @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column prop="name" label="姓名" width="180">
                </el-table-column>

                <el-table-column prop="region" label="姓名" width="180">
                </el-table-column>

                <el-table-column prop="date1" label="姓名" width="180">
                </el-table-column>

                <el-table-column prop="date2" label="姓名" width="180">
                </el-table-column>

                <el-table-column prop="type" label="姓名" width="180">
                </el-table-column>
                <el-table-column prop="resource" label="姓名" width="180">
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" class="el-icon-edit-outline" size="max"
                            @click="handleEdit(scope.row)"></el-button>
                        <el-button size="max" class="el-icon-delete" type="danger" @click="handleDelete(scope.row)">
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </template>
        <!-- 输出的弹框 -->

        <el-dialog title="提示" :visible.sync="dialogVisible" width="40%">
            <span>

                <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="活动名称">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item>
                    <el-form-item label="活动区域">
                        <el-select v-model="form.region" placeholder="请选择活动区域">
                            <el-option label="北京" value="北京"></el-option>
                            <el-option label="上海" value="上海"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="活动时间">
                        <el-col :span="11">
                            <el-date-picker type="date" placeholder="选择日期" v-model="form.date1" style="width: 100%;">
                            </el-date-picker>
                        </el-col>
                        <el-col class="line" :span="2">-</el-col>
                        <el-col :span="11">
                            <el-time-picker placeholder="选择时间" v-model="form.date2" style="width: 100%;">
                            </el-time-picker>
                        </el-col>
                    </el-form-item>
                    <el-form-item label="活动性质">
                        <el-checkbox-group v-model="form.type">
                            <el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
                            <el-checkbox label="地推活动" name="type"></el-checkbox>
                            <el-checkbox label="线下主题活动" name="type"></el-checkbox>
                            <el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item label="特殊资源">
                        <el-radio-group v-model="form.resource">
                            <el-radio label="线上品牌商赞助"></el-radio>
                            <el-radio label="线下场地免费"></el-radio>
                        </el-radio-group>
                    </el-form-item>

                </el-form>
            </span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="addButton">确 定</el-button>
            </span>

        </el-dialog>

        <div class="flex">
            <el-button style="margin: 20px 0;" type="danger" @click="pitchDelete">选中删除</el-button>
            <!-- 输出的弹框 -->
            <el-pagination @size-change="number" @size-change="handleSizeChange" @current-change="pageBtn"
                :page-sizes="[5, 8, 10, 20]" :page-size="pageNumber" layout="sizes, prev, pager, next" :total="total">
            </el-pagination>


            <!-- <el-pagination @current-change="pageBtn" background layout="prev, pager, next" :total="total"
                :page-size="7">

            </el-pagination> //分页按钮 -->
        </div>

        <!-- 编辑的弹框 -->
        <el-dialog title="编辑信息" :visible.sync="dialogVisible1" width="40%">
            <span>

                <el-form ref="editForm" :model="editForm" label-width="80px">
                    <el-form-item label="活动名称">
                        <el-input v-model="editForm.name"></el-input>
                    </el-form-item>
                    <el-form-item label="活动区域">
                        <el-select v-model="editForm.region" placeholder="请选择活动区域">
                            <el-option label="北京" value="北京"></el-option>
                            <el-option label="上海" value="上海"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="活动时间">
                        <el-col :span="11">
                            <el-date-picker type="date" placeholder="选择日期" v-model="editForm.date1"
                                style="width: 100%;">
                            </el-date-picker>
                        </el-col>
                        <el-col class="line" :span="2">-</el-col>
                        <el-col :span="11">
                            <el-time-picker placeholder="选择时间" v-model="editForm.date2" style="width: 100%;">
                            </el-time-picker>
                        </el-col>
                    </el-form-item>
                    <el-form-item label="活动性质">
                        <el-checkbox-group v-model="editForm.type">
                            <el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
                            <el-checkbox label="地推活动" name="type"></el-checkbox>
                            <el-checkbox label="线下主题活动" name="type"></el-checkbox>
                            <el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
                        </el-checkbox-group>
                    </el-form-item>
                    <el-form-item label="特殊资源">
                        <el-radio-group v-model="editForm.resource">
                            <el-radio label="线上品牌商赞助"></el-radio>
                            <el-radio label="线下场地免费"></el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-form>
            </span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible1 = false">取 消</el-button>
                <el-button type="primary" @click="editButton">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 编辑的弹框 -->

    </div>
</body>
<script src="./js/axios.js"></script>
<script src="./js/vue.js"></script>
<script src="./js/element.js"></script>
<!-- <script src="./js/jquery-1.12.3.js"></script> // jQuery -->
<script>
    var app = new Vue({
        el: '#app',
        data: {
            input: '',
            dialogVisible: false,//add 
            dialogVisible1: false, // edit
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                type: [],
                resource: '',
            },
            dataList: [],

            editForm: {  //编辑表单
                name: '',
                region: '',
                date1: '',
                date2: '',
                type: [],
                resource: '',
            },
            checkedAll: [],
            total: 0,
            pageSize: 1,// 前端传入的值
            pageNumber: 5,   // 每页几条数据
        },
        created() {
            this.render()
        },
        methods: {
            addBtn() {
                this.dialogVisible = true
            },
            searchBtn() {
                this.render()
            },
            number(item) {

                this.pageNumber = item
                this.render()

            },
            render() {   //渲染
                axios.get('/fdd', { params: { input: this.input, pageSize: this.pageSize, pageNumber: this.pageNumber } }).then(res => {
                    if (res.data.success) {
                        this.dataList = res.data.list
                        this.total = res.data.total
                    }
                })
            },
            pageBtn(item) {  // 分页事件
                // console.log(item);
                this.pageSize = item
                this.render()
            },
            addButton() {
                this.dialogVisible = false
                axios.get('add', { params: this.form }).then(res => {
                    console.log(this.dataList);
                    this.render()
                })
            },
            // 删除
            handleDelete(item) {  // 删除
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get('/rdd', { params: { id: item._id } }).then(res => {
                        console.log(this.dataList);
                        this.render()
                    })
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            },
            // Ba编辑路由
            handleEdit(item) {
                this.dialogVisible1 = true
                this.editForm = item
            },
            editButton() {
                axios.get('/xdd', { params: this.editForm }).then(res => {
                    this.dialogVisible1 = false
                    console.log(this.dataList);
                    this.render()
                })
            },


            handleSelectionChange(item) {
                this.checkedAll = item
            },
            pitchDelete() {
                console.log(this.checkedAll)
                axios.post('/allRemove', this.checkedAll).then(res => {
                    console.log(this.dataList);
                    this.render()
                })
            }

        },
    })
</script>

</html>